

************************
** Study 2: Figure S2.22
************************



** 2017 Results
***************

* Covariates macro
global covars_binaries = "gender1 gender2 gender3 agecat1 agecat2 agecat3 agecat4 agecat5 agecat6 edu1 edu2 edu3 edu4 edu5 edu6 pol_interest1 pol_interest2 pol_interest3 pol_interest4 lr0 lr1 lr2 lr3 lr4 lr5 lr6 lr7 lr8 lr9 lr10 vote2015_1 vote2015_2 vote2015_3 vote2015_4 vote2015_5 vote2015_6 vote2015_7 vote2015_8 vote2015_9 vote2015_10 refvote2016_1 refvote2016_2 refvote2016_3 region1 region2 region3"

* Open dataset
use "LondonBridgeAttack2017.dta", replace

* Running variable (event time)
sum statadate if postattack == .
gen eventtime = statadate - 20973
tab eventtime postattack

* Regressions
foreach dv of varlist sec imm britid englid {
reg `dv' i.postattack $covars_binaries if statadate >= td(31may2017)
estimates store `dv'1
reg `dv' i.postattack##c.eventtime $covars_binaries if statadate >= td(31may2017)
estimates store `dv'2
}

* Results table
gen count = _n
gen var = "D" in 1
replace var = "D (multiplicative)" in 2
replace var = "Days" in 3
replace var = "D*Days" in 4
foreach dv of varlist sec imm britid englid {
gen n_`dv' = .
gen coef_`dv' = .
gen se_`dv' = .
gen ll_`dv' = .
gen ul_`dv' = .
sum `dv'
gen sd_`dv' = `r(sd)'
gen d_`dv' = .
gen dlow_`dv' = .
gen dup_`dv' = .
estimates restore `dv'1
replace n_`dv' = `e(N)'
replace coef_`dv' = _b[1.postattack] in 1
replace se_`dv' = _se[1.postattack] in 1
estimates restore `dv'2
replace coef_`dv' = _b[1.postattack] in 2
replace se_`dv' = _se[1.postattack] in 2
replace coef_`dv' = _b[eventtime] in 3
replace se_`dv' = _se[eventtime] in 3
replace coef_`dv' = _b[1.postattack#eventtime] in 4
replace se_`dv' = _se[1.postattack#eventtime] in 4
replace ll_`dv' = coef_`dv' - 1.96*se_`dv'
replace ul_`dv' = coef_`dv' + 1.96*se_`dv'
replace d_`dv' = coef_`dv'/sd_`dv'
replace dlow_`dv' = coef_`dv'/sd_`dv' - 1.96*se_`dv'/sd_`dv'
replace dup_`dv' = coef_`dv'/sd_`dv' + 1.96*se_`dv'/sd_`dv'
}
drop newid - eventtime _est*
keep in 1/4
gen year = 2017
order year

save "DaysInteraction2017.dta", replace




** 2019 Results
***************

* Covariates macro
global covars_binaries = "gender1 gender2 gender3 agecat1 agecat2 agecat3 agecat4 agecat5 agecat6 edu1 edu2 edu3 edu4 edu5 edu6 pol_interest1 pol_interest2 pol_interest3 lr0 lr1 lr2 lr3 lr4 lr5 lr6 lr7 lr8 lr9 lr10 vote2017_1 vote2017_2 vote2017_3 vote2017_4 vote2017_5 vote2017_6 vote2017_7 vote2017_8 vote2017_9 vote2017_10 vote2017_11 refvote2016_1 refvote2016_2 refvote2016_3 refvote2016_4 region1 region2 region3"

* Open dataset
use "LondonBridgeAttack2019.dta", replace

* Running variable (event time)
sum statadate if postattack == .
gen eventtime = statadate - 21882
tab eventtime postattack

* Regressions
foreach dv of varlist sec imm britid englid {
reg `dv' i.postattack $covars_binaries if statadate >= td(26nov2019)
estimates store `dv'1
reg `dv' i.postattack##c.eventtime $covars_binaries if statadate >= td(26nov2019)
estimates store `dv'2
}

* Results table
gen count = _n
gen var = "D" in 1
replace var = "D (multiplicative)" in 2
replace var = "Days" in 3
replace var = "D*Days" in 4
foreach dv of varlist sec imm britid englid {
gen n_`dv' = .
gen coef_`dv' = .
gen se_`dv' = .
gen ll_`dv' = .
gen ul_`dv' = .
sum `dv'
gen sd_`dv' = `r(sd)'
gen d_`dv' = .
gen dlow_`dv' = .
gen dup_`dv' = .
estimates restore `dv'1
replace n_`dv' = `e(N)'
replace coef_`dv' = _b[1.postattack] in 1
replace se_`dv' = _se[1.postattack] in 1
estimates restore `dv'2
replace coef_`dv' = _b[1.postattack] in 2
replace se_`dv' = _se[1.postattack] in 2
replace coef_`dv' = _b[eventtime] in 3
replace se_`dv' = _se[eventtime] in 3
replace coef_`dv' = _b[1.postattack#eventtime] in 4
replace se_`dv' = _se[1.postattack#eventtime] in 4
replace ll_`dv' = coef_`dv' - 1.96*se_`dv'
replace ul_`dv' = coef_`dv' + 1.96*se_`dv'
replace d_`dv' = coef_`dv'/sd_`dv'
replace dlow_`dv' = coef_`dv'/sd_`dv' - 1.96*se_`dv'/sd_`dv'
replace dup_`dv' = coef_`dv'/sd_`dv' + 1.96*se_`dv'/sd_`dv'
}
drop id - eventtime _est*
keep in 1/4
gen year = 2019
order year

save "DaysInteraction2019.dta", replace





** Figure
*********


* Bring data in correct shape
* Data preparations
foreach i in 2017 2019 {
use "DaysInteraction`i'.dta", replace
set obs 16
replace year = `i'
replace count = _n
gen cat = 1 in 1/4
replace cat = 2 in 5/8
replace cat = 3 in 9/12
replace cat = 4 in 13/16
gen y = 0.85 in 1
replace y = count - .85 in 2/4
replace y = 0.8 in 5
replace y = count - 4.85 in 6/8
replace y = 0.8 in 9
replace y = count - 8.85 in 10/12
replace y = 0.8 in 13
replace y = count - 12.85 in 14/16
sum n_sec
gen label = "Security ({it:N} = `r(mean)')" if cat == 1
sum n_imm
replace label = "Immigration ({it:N} = `r(mean)')" if cat == 2
sum n_britid
replace label = "British ID ({it:N} = `r(mean)')" if cat == 3
sum n_englid
replace label = "English ID ({it:N} = `r(mean)')" if cat == 4
gen coef = d_sec in 1/4
gen ll = dlow_sec in 1/4
gen ul = dup_sec in 1/4
forvalues j = 1/4 {
sum d_imm in `j'
replace coef = `r(mean)' if count == `j'+4
sum dlow_imm in `j'
replace ll = `r(mean)' if count == `j'+4
sum dup_imm in `j'
replace ul = `r(mean)' if count == `j'+4
sum d_britid in `j'
replace coef = `r(mean)' if count == `j'+8
sum dlow_britid in `j'
replace ll = `r(mean)' if count == `j'+8
sum dup_britid in `j'
replace ul = `r(mean)' if count == `j'+8
sum d_englid in `j'
replace coef = `r(mean)' if count == `j'+12
sum dlow_englid in `j'
replace ll = `r(mean)' if count == `j'+12
sum dup_englid in `j'
replace ul = `r(mean)' if count == `j'+12
}
gen model = 2
replace model = 1 in 1
replace model = 1 in 5
replace model = 1 in 9
replace model = 1 in 13
order year count cat model label y coef ll ul
save "DaysInteraction`i'a.dta", replace
}
use "DaysInteraction2017a.dta", replace
append using "DaysInteraction2019a.dta"
replace cat = cat + 4 if year == 2019
labmask cat, values(label)


* Graph
twoway ///
	(scatter y coef if model == 1, mcolor(gs12) msymbol(o) msize(medsmall)) ///
	(rspike ll ul y if model == 1, lcolor(gs12) horizontal) ///
	(scatter y coef if model == 2, mcolor(gs2) msymbol(s) msize(medsmall)) ///
	(rspike ll ul y if model == 2, lcolor(gs2) horizontal) ///
	, ///
	by(cat, cols(4) noixtitle noixlabel graphregion(fcolor(white) lcolor(white)) bgcolor(white) note("")) ///
	ytitle("") yscale(reverse range(0.55 3.3)) yscale(noline) ///
	ylabel(1 "Post-attack" 2 "Days" 3 "Post * days", angle(horizontal) nogrid) ///
	xtitle("Effect on political attitudes (Cohen's {it:d})", margin(small)) xscale(noline) ///
	xlabel(-0.10(.10).30, tlcolor(black)) xmlabel(-0.10(0.05)0.30, ) ///
	legend(order(1 3) label(1 "Without interaction") label(3 "With interaction") cols(2) pos(6)size(small) colgap(*1) keygap(*1) region(lstyle(none) lcolor(white))) ///
	xline(0, lwidth(thin) lpattern(solid) lcolor(black) extend) ///
	subtitle(, size(medsmall) align(middle) margin(small) nobox fcolor(white))  ///
	graphregion(fcolor(white) ifcolor(white) lcolor(white)) plotregion(fcolor(white) lcolor(black)) bgcolor(white) ///
	graphregion(fcolor(white) ifcolor(white)) plotregion(fcolor(white) lcolor(black))  bgcolor(white) ///
	scheme(s2mono) xsize(12) ysize(8) 
	
	
* Manual edits
gr_edit .b1title.style.editstyle size(relative3) editcopy
gr_edit .legend.plotregion1.label[1].style.editstyle size(relative3) editcopy
gr_edit .legend.plotregion1.label[2].style.editstyle size(relative3) editcopy
gr_edit .note.style.editstyle size(vsmall) editcopy
gr_edit .plotregion1.xaxis1[5].style.editstyle majorstyle(tickstyle(show_labels(yes))) editcopy
gr_edit .plotregion1.subtitle[1].text = {}
gr_edit .plotregion1.subtitle[1].text.Arrpush `"Security"'
gr_edit .plotregion1.subtitle[1].text.Arrpush `"({it:N} = 28943)"'
// subtitle[1] edits
gr_edit .plotregion1.subtitle[2].text = {}
gr_edit .plotregion1.subtitle[2].text.Arrpush `"Immigration"'
gr_edit .plotregion1.subtitle[2].text.Arrpush `"({it:N} = 28713)"'
// subtitle[2] edits
gr_edit .plotregion1.subtitle[3].text = {}
gr_edit .plotregion1.subtitle[3].text.Arrpush `"British identity"'
gr_edit .plotregion1.subtitle[3].text.Arrpush `"({it:N} = 26806)"'
// subtitle[3] edits
gr_edit .plotregion1.subtitle[4].text = {}
gr_edit .plotregion1.subtitle[4].text.Arrpush `"English identity"'
gr_edit .plotregion1.subtitle[4].text.Arrpush `"({it:N} = 17628)"'
// subtitle[4] edits
gr_edit .plotregion1.subtitle[5].text = {}
gr_edit .plotregion1.subtitle[5].text.Arrpush `"Security"'
gr_edit .plotregion1.subtitle[5].text.Arrpush `"({it:N} = 25190)"'
// subtitle[5] edits
gr_edit .plotregion1.subtitle[6].text = {}
gr_edit .plotregion1.subtitle[6].text.Arrpush `"Immigration"'
gr_edit .plotregion1.subtitle[6].text.Arrpush `"({it:N} = 24965)"'
// subtitle[6] edits
gr_edit .plotregion1.subtitle[7].text = {}
gr_edit .plotregion1.subtitle[7].text.Arrpush `"British identity"'
gr_edit .plotregion1.subtitle[7].text.Arrpush `"({it:N} = 21441)"'
// subtitle[7] edits
gr_edit .plotregion1.subtitle[8].text = {}
gr_edit .plotregion1.subtitle[8].text.Arrpush `"English identity"'
gr_edit .plotregion1.subtitle[8].text.Arrpush `"({it:N} = 16223)"'
// subtitle[8] edits
gr_edit .plotregion1.style.editstyle margin(2.5 0 0 0) editcopy
// plotregion1 margin
gr_edit  .b1title.xoffset = 10
// bottom 1 edits
gr_edit  .legend.xoffset = 10
// legend edits
gr_edit  .AddTextBox added_text editor 70.43526376562814 -1.4
.added_text_new = 1
gr_edit  .added_text_rec = 1
gr_edit  .added_text[1].style.editstyle  angle(default) size( sztype(relative) val(3.4722) allow_pct(1)) color(black) horizontal(left) vertical(middle) margin( gleft( sztype(relative) val(0) allow_pct(1)) gright( sztype(relative) val(0) allow_pct(1)) gtop( sztype(relative) val(0) allow_pct(1)) gbottom( sztype(relative) val(0) allow_pct(1))) linegap( sztype(relative) val(0) allow_pct(1)) drawbox(no) boxmargin( gleft( sztype(relative) val(0) allow_pct(1)) gright( sztype(relative) val(0) allow_pct(1)) gtop( sztype(relative) val(0) allow_pct(1)) gbottom( sztype(relative) val(0) allow_pct(1))) fillcolor(bluishgray) linestyle( width( sztype(relative) val(.2) allow_pct(1)) color(black) pattern(solid) align(inside)) box_alignment(east) editcopy
gr_edit  .added_text[1]._set_orientation vertical
gr_edit  .added_text[1].text = {}
gr_edit  .added_text[1].text.Arrpush 2017
// editor text[1] edits
gr_edit  .AddTextBox added_text editor 35 -1.4
gr_edit  .added_text_new = 2
gr_edit  .added_text_rec = 2
gr_edit  .added_text[2].style.editstyle  angle(default) size( sztype(relative) val(3.4722) allow_pct(1)) color(black) horizontal(left) vertical(middle) margin( gleft( sztype(relative) val(0) allow_pct(1)) gright( sztype(relative) val(0) allow_pct(1)) gtop( sztype(relative) val(0) allow_pct(1)) gbottom( sztype(relative) val(0) allow_pct(1))) linegap( sztype(relative) val(0) allow_pct(1)) drawbox(no) boxmargin( gleft( sztype(relative) val(0) allow_pct(1)) gright( sztype(relative) val(0) allow_pct(1)) gtop( sztype(relative) val(0) allow_pct(1)) gbottom( sztype(relative) val(0) allow_pct(1))) fillcolor(bluishgray) linestyle( width( sztype(relative) val(.2) allow_pct(1)) color(black) pattern(solid) align(inside)) box_alignment(east) editcopy
gr_edit  .added_text[2]._set_orientation vertical
gr_edit  .added_text[2].text = {}
gr_edit  .added_text[2].text.Arrpush 2019
// editor text[2] edits	
gr_edit .gmetric_mult = 1.00
	





** Tidy Up
**********

erase "DaysInteraction2017.dta"
erase "DaysInteraction2019.dta"
erase "DaysInteraction2017a.dta"
erase "DaysInteraction2019a.dta"

